package com.csun.nusing.presenter;

import android.content.Context;

import com.csun.nusing.bean.UrlBean;
import com.csun.nusing.bean.jsonbean.BaseJsonBean;
import com.csun.nusing.presenter.inter.IFilePost;
import com.csun.nusing.util.SPUtils;
import com.csun.nusing.util.ToastUtil;
import com.google.gson.Gson;
import com.home.administrator.okhttplibrary.IOkTaskCallback;
import com.home.administrator.okhttplibrary.OkHttpTask;
import com.home.administrator.okhttplibrary.OkHttpTask.OkHttpTaskBuidler.OkType;

import java.util.HashMap;
import java.util.Map;

/**
 * 添加老人界面的presenter层 ClassName: AddOldrestPresenter
 * 
 * @Description: TODO
 * @author fzq
 * @date 2017-10-23
 */
public class AddOldrestPresenter extends BasePresenter<IFilePost> {

	private String authorization;
	private Context context;

	public AddOldrestPresenter(IFilePost view) {
		super(view);
	}

	public void postAddOlder(final Context mcontext, String oldname,
			String sex, String phone, String birthday, String egcontact,
			String egphone, String headId) {
		authorization = (String) SPUtils.get(context, "authorization", "");
		Map<String, String> param = new HashMap<String, String>();
		param.put("name", oldname);
		param.put("sex", sex);
		param.put("phone", phone);
		param.put("birthday", birthday);
		param.put("egcontact", egcontact);
		param.put("egphone", egphone);
		param.put("headpic", headId);
		OkHttpTask.newInstance(context).post(param, OkType.form)
				.addHeader("authorization", authorization)
				.enqueue(new IOkTaskCallback() {
					@Override
					public void onSuccess(String result) {
						if (result != null) {
							Gson gson = new Gson();
							BaseJsonBean bean = gson.fromJson(result,
									BaseJsonBean.class);
							if (bean != null) {
								ToastUtil.showMessage(mcontext,
										bean.getMessage());
							}
						}
					}
				}).start(UrlBean.NURSINGBYOLDMANURL);

	}

}
